﻿@{
    ViewData["Title"] = "Index";
    Layout = "~/Areas/Console/Views/Shared/_Layout.cshtml";
}
@section head{
    <script type="text/javascript">
        var table;
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table', 'form'], function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin
                , table = layui.table
                , parentFrameIndex = parent.layer.getFrameIndex(window.name);

            table.render({
                elem: '#table-datalist'
                , url: '/Console/Roles/GetListJson'
                , where: {
                    userType: $("#userType").val()
                }
                , title: '角色数据表'
                , cols: [[
                    { type: 'radio', fixed: 'left' }
                    , {
                        field: 'names', title: '名称', templet: function (res) {
                            return '<span lay-event="' + res.remark + '"></span>';
                        }
                    }
                ]]
                , page: false
                , done: function (res) {
                    if (res.count == 0) {
                        $(".layui-table-main").html('<div class="layui-none">' + top.lang.noData + '</div>');
                    }
                    layer.closeAll('loading');

                    /**多语言初始化 */
                    top.SetListPageLanguage(layui);
                }
            });

            /* 监听提交 */
            form.on('submit(submit-form)', function (data) {
                var checkStatus = table.checkStatus('table-datalist')
                    , data = checkStatus.data;
                var userType = $("#userType").val();
                $.ajax({
                    type: "POST",
                    url: "/Console/Roles/UpdateUserRolesItems",
                    data: {
                        ids: $("#ids").val(),
                        roleid: data[0].id,
                        userType: userType
                    }, // 你的formid
                    async: true,
                    error: function (request) {
                        alert("Connection error");
                    },
                    beforeSend: function (xhr) {
                        layui.layer.load();
                    },
                    success: function (data) {
                        var item = eval(data);
                        if (item.code == 0) {
                            /**提示语弹框 */
                            top.ShowMessageByKey(layui, "submitSuccess", 6, 1000, function () {
                                parent.layer.close(parentFrameIndex);
                                parent.renderTable();
                            });
                        } else {
                            /**提示语弹框 */
                            top.AlertByKey(layui, "submitFail", 0);
                        }
                        layer.closeAll('loading');
                    }
                });
                return false;
            });
        });
    </script>
}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="" lay-filter="component-form-group">
                <table class="layui-hide" id="table-datalist" lay-filter="table-datalist"></table>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <input id="ids" name="ids" value="@ViewBag.ids" type="hidden" />
                            <input id="userType" name="userType" value="@ViewBag.userType" type="hidden" />
                            <button lay-event="submitForm" class="layui-btn" lay-submit="" lay-filter="submit-form">立即提交</button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>